import { Vec2 } from "cc";
import { ecs } from "db://app-game/libs/ecs/ECS";
import { DBMap } from "../../../common/db/db-map/DBMap";
import { DBMapType } from "../../../common/db/db-map/DBMap.type";
import { StaticCreature } from "../../static-creature/StaticCreature";

export interface MapBaseInfo {
  id: string;
  pos: Vec2;
  minX: number;
  maxX: number;
  minY: number;
  maxY: number;
  rendering: boolean;
}

/** 障碍物基础信息 */
export interface ObstacleBaseInfo {
  id: string;
  pos: Vec2;
  minX: number;
  maxX: number;
  minY: number;
  maxY: number;
}

/** 地图基础组件 */
@ecs.register("MapModel")
export class MapModelComp extends ecs.Comp {
  db: DBMap = new DBMap();
  _id: number = -1;
  /** 地图编号 */
  get id(): number {
    return this._id;
  }
  set id(value: number) {
    this._id = value;
    this.db.init(value);
    this.data = this.db.data;
  }

  /** 地图数据 */
  data: DBMapType = null!;

  /** 分组地图宽 */
  chunkMapWidth: number = 1000;
  /** 分组地图高 */
  chunkMapHeight: number = 1000;

  /** 地图节点信息 */
  mapNodesMap: Map<string, MapBaseInfo> = new Map();
  /** 障碍物信息 */
  obstacleMap: Map<string, Map<string, ObstacleBaseInfo>> = new Map();
  /** 静态生物信息 */
  staticCreatureMap: Map<string, StaticCreature[]> = new Map();
  /** 瓷砖宽 */
  tileWidth: number = 20;
  /** 瓷砖高 */
  tileHeight: number = 20;

  reset(entity: ecs.Entity): void {
    this._id = -1;
    this.data = null!;
    this.tileWidth = 20;
    this.tileHeight = 20;
  }
}
